from flask import Blueprint, render_template
from exts import mail
from flask_mail import Message
from flask import request
import string
import random
# 在此蓝图的所有内容都以/auth开始
bp = Blueprint("auth", __name__, url_prefix="/auth")

@bp.route("/login")
def login():
    pass

@bp.route("/register")
def register():
    return render_template("register.html")

@bp.route("/captcha/email")
# 发送验验证码
def captcha_mail():
    email = request.args.get("email")
    source = string.digits
    captcha = random.sample(source, 4)
    captcha = "".join(captcha)
    message = Message(subject='验证码',recipients=["211087478@qq.com"], body=f'您的验证码是:{captcha}')
    mail.send(message)
    return 'success'

@bp.route("/mail/test")
def mail_test():
    # message = Message(subject='邮箱测试',recipients=["1443969851@qq.com"], )
    message = Message(subject='杨哥',recipients=["211087478@qq.com"], body='我是你骞哥')
    # mail.send(message)
    mail.send(message)
    return "邮件发送成功！"